﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
using LMKJ.Classes;

namespace LMKJ
{
    public partial class searchresidents : System.Web.UI.Page
    {
        private static ArrayList residentList = null;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                residentList = DatabaseManager.RetrieveAllResident();

                residentDlist.DataSource = residentList;
                residentDlist.DataBind();
            }
        }

        protected void searchBtn_Click(object sender, EventArgs e)
        {
            if (searchDdl.SelectedIndex == 0)
            {
                residentList.Clear();
                residentList.Add(DatabaseManager.RetrieveResidentByNric(searchTbx.Text));
            }
            else if (searchDdl.SelectedIndex == 1)
            {
                residentList = DatabaseManager.RetrieveResidentsByName(searchTbx.Text);
            }

            residentDlist.DataSource = residentList;
            residentDlist.DataBind();
        }

        protected void showAllBtn_Click(object sender, EventArgs e)
        {
            residentList = DatabaseManager.RetrieveAllResident();

            residentDlist.DataSource = residentList;
            residentDlist.DataBind();
        }
    }
}